package name.bingo.bing.pay.web.acid.service;

import com.google.common.base.Throwables;
import lombok.extern.slf4j.Slf4j;
import name.bingo.bing.pay.web.acid.dao.AcAccountDao;
import name.bingo.bing.pay.web.acid.model.AcAccount;
import name.bingo.bing.pay.web.acid.service.AcAccountReadService;
import name.bingo.common.model.PageInfo;
import name.bingo.common.model.Paging;
import name.bingo.common.model.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 璇绘湇鍔″疄鐜扮被
 *
 * @author [ your email ]
 * @date 2019-03-19 14:11:53
 * Created by CodeGen .
 */
@Slf4j
@Service
public class AcAccountReadServiceImpl implements AcAccountReadService {

    @Autowired
    private AcAccountDao acAccountDao;

    @Override
    public Response<AcAccount> findById(Long id) {
        try {
            return Response.ok(acAccountDao.findById(id));
        } catch (Exception e) {
            log.error("failed to find ac account by id:{}, cause:{}", id, Throwables.getStackTraceAsString(e));
            return Response.fail("ac.account.find.fail");
        }
    }

    @Override
    public Response<Paging<AcAccount>> paging(Integer pageNo, Integer pageSize, Map<String, Object> criteria) {
        try {
            PageInfo pageInfo = new PageInfo(pageNo, pageSize);
            return Response.ok(acAccountDao.paging(pageInfo.getOffset(), pageInfo.getLimit(), criteria));
        } catch (Exception e) {
            log.error("failed to paging ac account by pageNo:{} pageSize:{}, cause:{}", pageNo, pageSize, Throwables.getStackTraceAsString(e));
            return Response.fail("ac.account.paging.fail");
        }
    }

    @Override
    public Response<List<AcAccount>> list(Map<String, Object> criteria) {
        try {
            return Response.ok(acAccountDao.list(criteria));
        } catch (Exception e) {
            log.error("failed to list ac account, cause:{}", Throwables.getStackTraceAsString(e));
            return Response.fail("ac.account.list.fail");
        }
    }

}
